<?PHP
if (!session_start()) { session_start(); };
/*if (!isset($_SESSION['lgnapproved'])) {
	die(header('Location: login.php'));
}*/
include("functions.php");
include("cnnxn.php");
connect();

$SQLview='SELECT * FROM Results WHERE EventID='.$_GET['eid'].' ORDER BY Result ASC;';
//print $SQLview;
$sendit_view=mysqli_query($db,$SQLview) or die(mysqli_error($db));
$checkresults=mysqli_num_rows($sendit_view);

$SQLve='SELECT * FROM Events WHERE EventID='.$_GET['eid'].';';
$sendve=mysqli_query($db,$SQLve) or die(mysqli_error($db));
$RSve=mysqli_fetch_object($sendve);

$SQLge='SELECT * FROM Gender WHERE Gender LIKE "%'.$_GET['gen'].'%";';
$sendge=mysqli_query($db,$SQLge) or die(mysqli_error($db));
$RSge=mysqli_fetch_object($sendge);

//Set players dropdowns
$playersOptions='<option value=""></option>';
$SQLpl='SELECT * FROM Players WHERE GenderID='.$RSge->GenderID.' ORDER BY FirstName ASC, LastName ASC;';
$sendpl=mysqli_query($db,$SQLpl) or die(mysqli_error($db));
while ($RSpl=mysqli_fetch_object($sendpl)) {
	$playersOptions=$playersOptions.'<option value="'.$RSpl->PlayerID.'">'.$RSpl->FirstName.' '.$RSpl->LastName.'</option>';
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>daleclark.net</title>
<link type="text/css" rel="stylesheet" href="adminstyles.css" />
</head>
<body>
<div id="adminwrapper">
<div id="adminlogo"></div>
<?PHP navigation(); ?>
<div id="admincontent">
<h3>Results for: <?PHP print $RSve->StartDate.', '.$_GET['gen'].', '.$_GET['div'] ?></h3>

<p><a href="Events_viewall.php?tid=<?PHP print $_GET['tid']; ?>" style="font-size:10px; text-transform:uppercase;"><img src="../images/icon_back.png" style="border:none;" /> back to Events</a></p>
<?PHP if ($RSve->TeamSize==2) { $sowide='500'; } else { $sowide='750'; } ?>
<div style="float:left; width:<?PHP print $sowide; ?>px; padding-right:25px; margin-right:25px; border-right:1px solid #FFFFFF;">
<?PHP if ($checkresults>=1) { ?>
<form id="resultsform" method="post" action="Results_mod.php?tid=<?PHP print $_GET['tid']; ?>">
<?PHP } else { ?>
<form id="resultsform" method="post" action="Results_add.php?tid=<?PHP print $_GET['tid']; ?>">
<?PHP } ?>
<?PHP 
$backgroundcolor="#2883D4";
if ($checkresults>=1) {
	while ($RSview=mysqli_fetch_object($sendit_view)) {
		if ($backgroundcolor=="#2883D4") {
			$backgroundcolor="#2F93E9";
		} else {
			$backgroundcolor="#2883D4";
		}
		
		$SQLgt='SELECT * FROM Teams WHERE TeamID='.$RSview->TeamID.';';
		$sendgt=mysqli_query($db,$SQLgt) or die(mysqli_error($db));
		
		
		print '<div style="background:'.$backgroundcolor.'; width:'.$sowide.'px; padding:2px 2px 2px 5px;"><span class="deletespan"><a href="Results_del.php?tid='.$_GET['tid'].'&eid='.$_GET['eid'].'&gen='.$_GET['gen'].'&div='.$_GET['div'].'&rid='.$RSview->ResultID.'" class="deletelink" title="DELETE" onclick="return confirm(\'Are sure you want to PERMANENTLY DELETE this Team?\nNOTE: This will also alter the number of Teams in the event.\')"><img src="../images/icon_delete.png" height="12px" border="0" /></a></span><input type="hidden" name="EventID" value="'.$RSview->EventID.'" />&nbsp;';
		while ($RSgt=mysqli_fetch_object($sendgt)) {		
			$SQLgps='SELECT * FROM Players WHERE PlayerID='.$RSgt->PlayerID.';';
			$sendgps=mysqli_query($db,$SQLgps) or die(mysqli_error($db));
			$RSgps=mysqli_fetch_object($sendgps);
			print '<input type="text" name="" value="'.$RSgps->FirstName.' '.$RSgps->LastName.'" />&nbsp;';
		}
		
		print '<input type="text" name="" value="'.$RSview->Result.'" style="width:25px;" /><div class="clear"></div></div>';
	}
} else {
	$rowflag=1;
	while($rowflag<=$RSve->NumberOfTeams) {
		if ($backgroundcolor=="#2883D4") {
			$backgroundcolor="#2F93E9";
		} else {
			$backgroundcolor="#2883D4";
		}
		print '<div style="background:'.$backgroundcolor.'; width:'.$sowide.'px; padding:2px 2px 2px 5px;"><input type="hidden" name="EventID" value="'.$_GET['eid'].'" />&nbsp;<select name="'.$rowflag.'-name01">'.$playersOptions.'</select>&nbsp;<select name="'.$rowflag.'-name02">'.$playersOptions.'</select>&nbsp;';
		if ($RSve->TeamSize==4) {
			print '<select name="'.$rowflag.'-name03">'.$playersOptions.'</select>&nbsp;<select name="'.$rowflag.'-name04">'.$playersOptions.'</select>&nbsp;';
		}
		print '<input type="text" name="'.$rowflag.'-finish" style="width:25px;" /><div class="clear"></div></div>';
		$rowflag++;
	}
}
?>
<input type="submit" value=" submit " name="submit" />
</form>

<div class="clear"></div>
<p>&nbsp;</p>
</div>

</div>
</div>
</body>
</html>
<?PHP
mysqli_close($db);
?>